/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input, Radio, Select,   Icon,
  Upload, } from 'antd';
import {connect} from 'dva';
import moment from 'moment'
import request from '@/utils/request';
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      users:[]
    };
  }

  componentDidMount() {
    const that=this;
    request(`/search_users`, {
      method: 'GET',
      params:{
        per_page:100
      }
    }).then((response)=> {
      console.log('users', response)
      if(response.status===200){
        that.setState({
          users:response.data.data
        })
      }
    })
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 6},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    const props = {
      onRemove: (file) => {
        this.setState(({ fileList }) => {
          const index = fileList.indexOf(file);
          const newFileList = fileList.slice();
          newFileList.splice(index, 1);
          return {
            fileList: newFileList,
          };
        });
      },
      beforeUpload: (file) => {
        this.setState(({ fileList }) => ({
          fileList: [file],
        }));
        return false;
      },
      fileList: this.state.fileList,
    };
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               仓库名称
            </span>
            )}
          >
            {getFieldDecorator('name', {
              initialValue: this.props.editRecord?this.props.editRecord.name:"",
              rules: [{ required: true, message: '请输入仓库名称' }],
            })(
              <Input />
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               仓库地址
            </span>
            )}
          >
            {getFieldDecorator('address', {
              initialValue: this.props.editRecord?this.props.editRecord.address:"",
              rules: [{ required: true, message: '请输入仓库地址' }],
            })(
              <Input />
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
              管理员
            </span>
            )}>
            {getFieldDecorator('administrator_id', {
              initialValue: this.props.editRecord?this.props.editRecord.administrator_id:"",
              rules: [{required: true, message:'管理员不能为空'}],
            })(
              <Select  >
                { this.state.users.map((item, key) => {
                  return (
                    <Option key={item.id}  value={item.id.toString()}>{item.username}</Option>
                  )
                }) }
              </Select>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               备注
            </span>
            )}
          >
            {getFieldDecorator('remark', {
              initialValue: this.props.editRecord?this.props.editRecord.remark:"",
            })(
              <Input />
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


